/*
 *--------------------------------------------------------------------------
 *   Battlefield - A Realtime Network Multiplayer Game
 *   =====================================================
 *   Developed by Group D02 - 2009/2010 Semester 4 - CS2103
 *     Harry Nguyen Duy Hoang <nnduyhoang@yahoo.co.uk>
 *     Kent Chng Siang Rong <fivefootway@gmail.com>
 *     Lim Yong Peng <limpeng1986@gmail.com>
 *     Loh Xiankun <u0807185@nus.edu.sg>
 *   Instructed by
 *     Dr. Damith C.Rajapakse <damith@gmail.com>
 *   =====================================================
 *   $Id: Cell.java 607 2010-07-27 07:16:34Z Harry $
 *   $LastChangedDate: 2010-07-27 07:16:34 +0000 (Tue, 27 Jul 2010) $
 *   $LastChangedBy: Harry $
 *--------------------------------------------------------------------------
 */
package battlefield.entity;

import battlefield.state.CellState;
import java.io.Serializable;

/**
 *
 * @author Harry Nguyen
 */
public class Cell implements Serializable {

    /**
     * width of each cell
     */
    public static final int WIDTH = 32;
    /**
     * height of each cell
     */
    public static final int HEIGHT = 32;
    private CellImage backgroundImage;
    private CellImage destroyedImage;
    private CellState state;

    /**
     * Constructs the Cell object and initialize the state to unspecific
     */
    public Cell() {
        this.state = CellState.UNSPECIFIED;
    }

    /**
     * Returns the background image of the cell
     *
     * @return      CellImage Object
     * @see         CellImage
     */
    public CellImage getBackgroundImage() {
        return backgroundImage;
    }

    /**
     * Set the background image of the cell
     *
     * @param backgroundImage
     */
    public void setBackgroundImage(CellImage backgroundImage) {
        this.backgroundImage = backgroundImage;
    }

    /**
     * Returns the image of the what the cell would look like after it is destroyed
     *
     * @return      the image at the specified URL
     * @see         CellImage
     */
    public CellImage getDestroyedImage() {
        return destroyedImage;
    }

    /**
     * Set the image of what the cell would look like after being destroyed
     *
     * @param destroyedImage
     */
    public void setDestroyedImage(CellImage destroyedImage) {
        this.destroyedImage = destroyedImage;
    }

    /**
     * Returns the state of the cell
     * 
     * @return      State of the cell
     * @see         CellState
     */
    public CellState getState() {
        return state;
    }

    /**
     * Set the state of the cell
     *
     * @param  state of the cell
     * @see  CellState
     */
    public void setState(CellState state) {
        this.state = state;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }

        if (!(obj instanceof Cell)) {
            return false;
        }

        Cell c = (Cell) obj;

        if (this.getBackgroundImage() == null || !this.getBackgroundImage().equals(c.getBackgroundImage())) {
            return false;
        }

        if (this.getDestroyedImage() == null || !this.getDestroyedImage().equals(c.getDestroyedImage())) {
            return false;
        }

        return this.getState() == c.getState();
    }

    @Override
    public int hashCode() {
        int hash = 3;
        hash = 59 * hash + (this.backgroundImage != null ? this.backgroundImage.hashCode() : 0);
        hash = 59 * hash + (this.destroyedImage != null ? this.destroyedImage.hashCode() : 0);
        hash = 59 * hash + (this.state != null ? this.state.hashCode() : 0);
        return hash;
    }
}
